package lucene_db;
import java.sql.*;
public class DB {
     public static String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
     public static String connString="jdbc:sqlserver://localhost:1433;databaseName=crawler;integratedSecurity=true;";
     
     public static Connection getConnection(){
          Connection conn=null;
          try {
               Class.forName(driver).newInstance();
               conn=DriverManager.getConnection(connString);
          } catch (InstantiationException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          } catch (IllegalAccessException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          } catch (ClassNotFoundException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
               System.err.println("驱动未找到");
          } catch (SQLException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
               System.err.println("数据库连接失败");
          }
          return conn;
     }
     public static void closeConnection(Connection conn) {
          try {
               conn.close(); // 关闭连接
          } catch (SQLException ex) {
               ex.printStackTrace();
          }

     }
     public static void commitConnection(Connection conn){
          try {
               conn.setAutoCommit(false);
          } catch (SQLException e1) {
               // TODO Auto-generated catch block
               e1.printStackTrace();
          }
     }
//     public static void main(String[] args) {
//          // TODO Auto-generated method stub
//          Connection conn=DB.getConnection();
//          System.out.println("success!!");
//          DB.closeConnection(conn);
//          }
}

